# 将字典或列表以JSON格式保存到文件中

import json


def main():
    my_dict = {
        "name": "罗昊",
        "age": 38,
        "qq": 957658,
        "friends": ["王大锤", "白元芳"],
        "cars": [
            {"brand": "BYD", "max_speed": 180},
            {"brand": "Audi", "max_speed": 280},
            {"brand": "Benz", "max_speed":320 }
        ]
    }
    try:
        with open("../res/data.json", "w", encoding="utf-8") as fs:
            json.dump(my_dict, fs)
    except IOError as e:
        print(e)
    print("保存数据完成！")


if __name__ == "__main__":
    main()